<?php
	class messagepage
	{
		private $page;
		
		public function __construct()
		{
			$dbAcces = new db();
			$this->page = array();
			$this->page['title'] = "Message";
			$postQuery = $dbAcces->get("blogID, author, title, summary, tumbnail","","bl_post");
			$posts = array();
			while($row = mysql_fetch_array($postQuery))
			{
				$author = $dbAcces->get("name","userID = '"+$row["author"]+"'","bl_members");
				$authorRow = mysql_fetch_row($author);
				array_push($posts, array("id" => $row["blogID"], "authorID" => $row["author"], "authorName" => $authorRow[0], "title" => $row["title"], "summary" => $row["summary"], "tumbnail" => $row["tumbnail"], ));
			}
			$this->page['content'] = "";
			if(count($posts) != 0)
			{
				$this->page['content'] = "<table id='blogPostTable'>
				<thead><tr><th>Title</th><th>summary</th><th>author</th><th>options</th></tr></thead>
				<tbody>";
				for($i = 0; $i < count($posts); $i++)
				{
					$this->page['content'] .= "
					<tr";
					if($i % 2)
					{
						$this->page['content'] .= 	" class='odd'";
					}
					else
					{
						$this->page['content'] .= 	" class='even'";
					}
					$this->page['content'] .= "><td><a href='../?page=post&id=".$posts[$i]["id"]."' target='blank'>".$posts[$i]["title"]."</a></td><td>".$posts[$i]["summary"]."</td><td><a href='?page=user&id=".$posts[$i]["authorID"]."'>".$posts[$i]["authorName"]."</a></td><td><a href='?page=MessageEdit&id=".$posts[$i]["id"]."'><img src='../resoursces/img/icons/edit.png' title='edit'/></a><a href='?page=deletePost&id=".$posts[$i]["id"]."'><img src='../resoursces/img/icons/delete.png' title='delete'/></a></td></tr>";
				}
				$this->page['content'] .= "</tbody></table><br />
				";
			}
			$this->page['content'] .= "<a href='?page=newMessage'>new post</a>";
		}
		
		public function getPage()
		{
			$page = $this->page;
			require_once("templates/Main.php");
		}
	}
?>